package com.thread.thread;

/**
 * @author wangyingjie
 * @date
 * @remark
 */
public class MyThread_1 extends Thread {

    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println(getName()+"===> "+i);
        }
    }

    public static void main(String[] args) {//主线程

        MyThread_1 myThread_1 = null;
        for (int i = 0; i < 100; i++) {
            System.out.println(Thread.currentThread().getName()+"===> "+i);
            if (i == 20) {
                myThread_1 = new MyThread_1();
                myThread_1.start();//子线程
            }
            //子线程死亡后，再调用start会报错
            if (i>20 && !myThread_1.isAlive()){
                myThread_1.start();
            }
        }
    }
}
